$("#form-customerDetails-add").validate({
	rules:{
		clueOperationType:{
			required:true,
		},
		isOwnself:{
			required:true,
		},
		typeId:{
			required:true,
		},
		questionId:{
			required:true,
		},
		detailId:{
			required:true,
		},
		content:{
			required:true,
		},
		suggestion:{
			required:true,
		},
	},
	submitHandler:function(form){
		add();
	}
});

function add() {
	var clueId = $("input[name='clueId']").val();
	var typeId = $("select[name='typeId']").val();
	var typeName = $("select[name='typeId'] option:selected").text();
	var questionId = $("select[name='questionId']").val();
	var questionType = $("select[name='questionId'] option:selected").text();
	var detailId = $("select[name='detailId']").val();
	var detailName = $("select[name='detailId'] option:selected").text();
	var content = $("textarea[name='content']").val();
	var suggestion = $("textarea[name='suggestion']").val();
	$.ajax({
		cache : true,
		type : "POST",
		url : ctx + "/module/customerClue/communicateSave",
		data : {
			"clueId": clueId,
			"typeId": typeId,
			"typeName": typeName,
			"questionId": questionId,
			"questionType": questionType,
			"detailId": detailId,
			"detailName": detailName,
			"content": content,
			"suggestion": suggestion,
		},
		async : false,
		error : function(request) {
			$.modalAlert("系统错误", "error");
		},
		success : function(data) {
			if (data.code == 0) {
				detailsAdd();
			} else {
				$.modalAlert(data.msg, "error");
			}

		}
	});
}

function detailsAdd() {
	var clueId = $("input[name='clueId']").val();
	var clueOperationType = $("select[name='clueOperationType']").val();
	var isOwnself = $("input[name='isOwnself']").val();
	var isHandle = $("input[name='isHandle']").val();
	$.ajax({
		cache : true,
		type : "POST",
		url : ctx + "/module/customerClue/detailsSave",
		data : {
			"clueId": clueId,
			"clueOperationType": clueOperationType,
			"isOwnself": isOwnself,
			"isHandle": isHandle,
		},
		async : false,
		error : function(request) {
			$.modalAlert("系统错误", "error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("新增成功,正在刷新数据请稍后……",{icon:1,time: 500,shade: [0.1,'#fff']},function(){
					$.parentReload();
				});
			} else {
				$.modalAlert(data.msg, "error");
			}

		}
	});
}

window.onload = function(){ 
　　　　js_switch(1);
} 

function js_switch(a){
	var s1 = $(".diss1");
	var s2 = $(".diss2");
	var s3 = $(".diss3");
	if(a==1){
		$(s1).show();
		$(s2).hide();
		$(s3).hide();
		$("th[id='ptype']").text('二期床位');
	}else if(a==2){
		$(s2).show();
		$(s1).hide();
		$(s3).hide();
		$("th[id='ptype']").text('乐享旅游');
	}else if(a==3){
		$(s3).show();
		$(s1).hide();
		$(s2).hide();
		$("th[id='ptype']").text('康复项目');
	}
}

function changeSelect(){
	var questionId = $("select[name='questionId']").val();
	$.ajax({
        type: "GET",
        url: ctx + "/module/customerClueDetail/selectList",
        data : {
        	"questionId": questionId
        },
        success: function(result) {
        	//获取第二个下拉框的对象
        	var spec = document.getElementById('detailId');
        	//每次获取数据前先清空
        	$(spec).empty();
        	for(var i=0;i<result.length;i++){//循环遍历数组
        		//将数组的值依次赋给第二个下拉框
        		spec[i] = new Option(result[i].detailType,result[i].detailId);
			}
        }
    });
}











